# Replication Package: Demographics, Automation, and Comparative Advantage

## Overview
This folder contains all files needed to replicate the analysis in "Demographics, Automation, and Comparative Advantage." The paper shows that aging drives capital intensity (Z1=41.4*** full sample, 47.8*** non-OECD) and labor productivity (Z1=1.68*** log), but capital intensity AMPLIFIES the demographic effect on current accounts (-109% attenuation) rather than mediating it. In OECD only, capital intensity mediates (136% attenuation with sign flip).

## Requirements
- Python 3.10+
- pandas, numpy, scipy, statsmodels
- Data files in data/processed/

## Structure
- `scripts/` — Analysis scripts (run in phase order)
- `src/` — Shared modules (PanelGLS estimator, data loading, country classifications)
- `data/processed/` — Processed panel data (automation_panel.csv)
- `output/tables/` — Generated output tables
- `paper/` — Paper manuscript and references

## Reproduction
Run scripts in numerical phase order:
```
python scripts/phase1_data_assembly.py
python scripts/phase2_demographics_automation.py
python scripts/phase3_automation_ca_mediation.py
python scripts/phase4_comparative_advantage.py
python scripts/phase5_dynamics.py
python scripts/phase6_robustness.py
```

## Data Sources
- UN World Population Prospects 2024
- IMF World Economic Outlook
- Penn World Table 10.01 (.dta format — use pd.read_stata())
- Chinn-Ito KAOPEN Index
- Lane & Milesi-Ferretti External Wealth of Nations

## Notes
- All analysis uses the 140-country expanded panel (EBA-49 + SSA-20 + EU expansion + Tier 1 expansion)
- The `src/` modules are from the multilateral/followup project and contain the expanded country lists
- PWT data is in .dta format; use pd.read_stata() to load
- GVC/trade effects have opposite signs: full Z1=98.9**, OECD Z1=-300.5***
- Low-income strongest for capital intensity; middle for productivity
